<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>停车场管理</title>
<jsp:include page="../../import.jsp" flush="true" />
<jsp:include page="assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div class="searchArea">
		<!-- 搜索表单开始 -->
		<form id="searchBar">
			<div class="fieldset1 clearFix">
				<div class="FXBR">
					<div class="fieldBox">
						<div class="label">停车场名称</div>
						<div class="field">
							<input type="text" id="parkNm" name="parkNm" class="ui-textbox" ligerui="width: 160" value="">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">停车场编号</div>
						<div class="field">
							<input type="text" id="parkCd" name="parkCd" class="ui-textbox" ligerui="width: 160" value="">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">资产管理员(姓名)</div>
						<div class="field">
							<input type="text" id="assManagers" name="assManagers" class="ui-textbox" ligerui="width: 160" value="">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">续签状态</div>
						<div class="field">
							<select name="vFlag" id="vFlag" ligerui="width: 160">
								<option value="">请选择</option>
								<option value="1">未续签</option>
								<option value="2">已续签</option>
							</select>
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">停车场状态</div>
						<div class="field">
							<select name="parkStatus" id="parkStatus" ligerui="width: 160">
								<option value="">请选择</option>
								<option value="1">合作中</option>
								<option value="2">已到期</option>
							</select>
						</div>
					</div>
				</div>
				
				<div class="clearFix"></div>
				
				<!-- 表单按钮 -->
				<div class="btnsBox formBtns notRight">
					<span id="searchBtn" class="sq-button-round">查询</span>
					<span id="clearBtn" class="sq-button-round">清空</span>
					<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
					<span id="addBtn" class="sq-button-round" onclick="add();">新增</span>
					<%--<span id="downBtn" class="sq-button-round" onclick="downloadBtnEvent();">导出Excel</span>--%>
	            </div>
	            <!-- 合同到期提醒 -->
				<div class="disp_right">
					<span>
						<font color="blue"><i class="ico_flasher_blue"></i>合同到期前30天提醒</font>
						<font color="red"><i class="ico_flasher"></i>合同已经超期提醒</font>
					</span>
	            </div>
			</div>
		</form>
		<!-- 搜索表单结束 -->
	</div>
</div>

<!-- 列表显示块 -->
<div id="ligergrid1" class="sq-grid"></div>

<script type="text/javascript">
	var grid = null;
	$(function () {
	    initForm();//初始化表单
	    initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    searchBtnEvent();//查询按钮事件
	    clearBtnEvent();//清空按钮事件
	});
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url:'<%=path%>/ass/assParking/initList.do',
			method:'get',
			parms:getSearchParams(),
			columns:[
				{ display: '<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="合同到期提醒"></span>', 
					name: '', minWidth: 30, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '';
						if(rowdata.parkSt == "已到期"){//合同到期提醒
							h = '<i class="ico_flasher"></i>';
						}else if(rowdata.validSt == "未续签"){
							h = '<i class="ico_flasher_blue"></i>';
						}
						return h;
					}},
				{ display: '停车场编号', name: 'parkCd', width: 100, enabledSort:true},
				{ display: '停车场名称', name: 'parkNm', minWidth: 120, align:'left', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var provinceCity = rowdata.provinceCd+'-'+rowdata.cityCd;
						var h = '';
						h+= '<span class="gridTip" style="cursor: pointer;" title="' + value + '">';
						h+='<a href="javascript:showDetail(';
						h+="'"+rowdata.id+"'";
						h+=",'"+rowdata.validId+"'";
						h+=",'"+provinceCity+"'";
						h+=')">'+value+'</a>';
						h+='</span>';
						return h;
					}},
				{ display: '停车场地址', name: 'parkAddress', width: 150, align:'left', enabledSort:true,
		                render: function (item) {
		                	var h = '';
		                	if(item.parkAddress != null){
		                		h += '<span class="gridTip" style="cursor: pointer;" title="' + item.parkAddress + '">' + item.parkAddress + '</span>';
		                	}
		                	return h;
		                }},
				{ display: '所在城市', name: 'provinceCity', width: 120, align:'left', enabledSort:true,
					render:function (rowdata, rowindex, value){
						var h = rowdata.provinceCd+'-'+rowdata.cityCd;
						return h;
					}},
				{ display: '停车场联系人', name: 'contactNm', width: 120, enabledSort:true},
				{ display: '停车场联系人电话', name: 'contactTel', width: 120, enabledSort:true},
				{ display: '合同有效期', name: 'validDate', width: 150, enabledSort:true,
					render:function (rowdata, rowindex, value){
						var h = renderDate(rowdata.beginDt)+'-'+renderDate(rowdata.endDt);
						return h;
					}},
				{ display: '资产管理员', name: 'assManagers', width: 150, align:'left', enabledSort:true,
		                render: function (item) {
		                	var h = '';
		                	if(item.assManagers != null){
		                		h += '<span class="gridTip" style="cursor: pointer;" title="' + item.assManagers + '">' + item.assManagers + '</span>';
		                	}
		                	return h;
		                }},
				{ display: '停车场状态', name: 'parkSt', width: 80, align:'center', enabledSort:true},
				{ display: '续签状态', name: 'vFlag', width: 80, align:'center', enabledSort:true,
					render:function (rowdata, rowindex, value){
						var provinceCity = rowdata.provinceCd+'-'+rowdata.cityCd;
						var h = '';
						if(rowdata.validSt == "未续签"){
							h+='<a href="javascript:showRenew(';
							h+="'"+rowdata.id+"'";
							h+=",'"+rowdata.validId+"'";
							h+=",'"+provinceCity+"'";
		 					h+=")\">"+rowdata.validSt+"</a>";
						}else{
							h+=rowdata.validSt;
						}
						return h;
					}},
				getGridOperColumnContent()//操作列
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:'100%',
			heightDiff:-2,
			checkbox:true,//列表是否有选择框
			rownumbers:true//列表是否有行号
		});
		grid = liger.get("ligergrid1");
		grid.setHeight(100);
		grid.options.isSingleCheck = false;//列表是否为单选
	}
	
	//隐藏掉操作列
    function getGridOperColumnContent(){
		var data = {
			display:'操作',
			isSort:false,
			width:80,
			align:'center',
			render:function (rowdata, rowindex, value){
				var h="";
            	h+='<a class="sq-button-hasicon" alt="修改" href="javascript:modifyRow(';
                h+="'"+rowdata.id+"'";
                h+=",'"+rowdata.validId+"'";
                h+=")\"><i class=\"sqBtnIco_4\"></i>"+LogUtils.LOG_CMM_GRID_BTN_MODIFY+"</a>";
				return h;
			}
		};
		return data;
	}
	
	//清空按钮事件
	function clearBtnEvent(){
		$("#clearBtn").click(function(event) {
			$("#resetBtn").click();  //重置 input-text
			var form = liger.get("searchBar");
			form.setData({  //重置select等特殊表单
				"vFalg":"",
				"parkStatus":""
			});
		});
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		$("#searchBtn").click(function(event) {
			var form = new liger.get("searchBar");
			var data = form.getData();
			//alert(JSON.stringify(data));
			for (name in data){
				grid.setParm(name,data[name]);
			};
			grid.reload();
		});
	}
	
	//新增停车场
	function add() {
		//回调刷新列表
		var callback = function () {
			grid.reload();
		};
		Add_navTab("Ass_1"+Date.parse(new Date()), "新增停车场信息", '<%=path%>/ass/assParking/toAddPage.do?' , callback);
	}
	
	//修改停车场信息
	function modifyRow(_id, _validId){
		//回调刷新列表
		var callback = function () {
			grid.reload();
		};
		if(!_id){
			return;
		}//停车场ID为空不执行
		Add_navTab('Ass_2'+_id,'修改停车场信息','<%=path%>/ass/assParking/toModifyPage.do?id='+_id+'&validId='+_validId , callback);
	}
	
	//查看停车场信息
	function showDetail(_id, _validId, provinceCity){
		//回调刷新列表
		var callback = function () {
			grid.reload();
		};
		if(!_id){
			return;
		}//停车场ID为空不执行
		Add_navTab('Ass_3'+_id,'查看停车场信息','<%=path%>/ass/assParking/toDetailPage.do?id='+_id+'&validId='+_validId+'&provinceCity='+provinceCity , callback);
	}
	
	//查看停车场信息
	function showRenew(_id, _validId, provinceCity){
		//回调刷新列表
		var callback = function () {
			grid.reload();
		};
		if(!_id){
			return;
		}//停车场ID为空不执行
		Add_navTab('Ass_4'+_id,'停车场合同续签','<%=path%>/ass/assParking/toRenewPage.do?id='+_id+'&validId='+_validId+'&provinceCity='+provinceCity , callback);
	}
	
	//导出停车场信息
	function downloadBtnEvent(){
		var form = new liger.get("searchBar");
		var grid = liger.get("ligergrid1");
		var selectedRows = grid.getSelectedRows();
		var parkIds = new Array();
		for(var i=0;i<selectedRows.length;i++){
			var parkId = "'"+selectedRows[i].id+"'";
			parkIds[i] = parkId;
		}
        var data = form.getData();
        data["parkIds"] = JSON.stringify(parkIds);
		var wait_dialog = null;
		$.ajax({
			type: 'get',
			dataType:'json',
			url: '<%=path%>/ass/assParking/exportAssParking.do',
			data:data,
			beforeSend:function(){
				wait_dialog=$.ligerDialog.SQalert({content: '正在导出停车场信息...',SQ_type: "waitting"});
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					window.open(msg.data);
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			} 
		});
	}
	
</script>
</body>
</html>